import type { IQuery, IResponse } from '@/api/config/types';
import axios from 'axios';
import { IS_ENUM } from '@/enum/system';

export interface IMenu {
  menuId: string;
  menuName: string;
  parentName: string | null;
  parentId: string;
  orderNum: number;
  path: string;
  component: string;
  isFrame: IS_ENUM;
  isCache: string;
  menuType: 'M' | 'F' | 'C';
  visible: IS_ENUM;
  status: string;
  perms: string;
  icon: string;
  createBy: string;
  createTime: string;
  updateBy: string;
  updateTime: string;
  remark: string;
  params?: Record<string, unknown>;
  children: IMenu[];
  meta: any;
}

const prefix = '/system/menu';

// 查询菜单列表
export const listMenu = (query: IQuery) => {
  return axios.get<IResponse<IMenu[]>>(`${prefix}/list`, {
    params: query,
  });
};

export const addMenu = (data: IMenu) => {
  return axios.post(`${prefix}`, data);
};

export const updateMenu = (data: IMenu) => {
  return axios.put(`${prefix}`, data);
};

export const deleteMenu = (id: string) => {
  return axios.delete(`${prefix}/${id}`);
};

export const getMenuById = (id: string) => {
  return axios.get<IResponse<IMenu>>(`${prefix}/${id}`);
};
